package com.cloud.school.bus.teacherhelper.protocol.baserequest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.message.BasicHeader;

import android.content.Context;
import android.text.TextUtils;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.network.BaseHttpRequest;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.RequestParams;
import com.cloud.school.bus.teacherhelper.include.Version;
import com.cloud.school.bus.teacherhelper.protocol.ProtocolDef;
/**
 * 用于POST请求
 * @author lenovo
 *
 */
public class BasePostHttpRequest extends BaseHttpRequest {

	protected String mMethod = "";
	protected RequestParams mRequestParams;

	public BasePostHttpRequest(Context context) {
		super(context);
	}

	@Override
	public Context getContext() {
		return mContextWeakReference.get();
	}

	@Override
	public String getAbsoluteUrl() {
		return ProtocolDef.DOMAIN + mMethod;
	}

	@Override
	public Header[] getHeaders() {
		List<Header> mHeaders = new ArrayList<Header>();
		mHeaders.add(new BasicHeader("apikey", "mactoprest"));
		mHeaders.add(new BasicHeader("Version", Version.versionName
				.substring(1)));
		if (!TextUtils
				.isEmpty(NetworkClient.getNetworkClient().getLoginToken())) {
			mHeaders.add(new BasicHeader("sid", NetworkClient
					.getNetworkClient().getLoginToken()));
		}
		Header[] headers = mHeaders.toArray(new Header[] {});
		return headers;
	}

	@Override
	public RequestParams getRequestParams() {
		return mRequestParams;
	}

	@Override
	public HttpEntity getRequestEntity() {
		return null;
	}

	@Override
	public String getPostContentType() {
		return null;
	}

	/**
	 * 在子类中得构造函数中调用
	 * 
	 * @param method
	 * @param requestMap
	 */
	protected void setRequestParam(String method, Map<String, String> requestMap) {
		mMethod = method;
		if (null != requestMap && 0 != requestMap.size()) {
			mRequestParams = new RequestParams(requestMap);
			
			DebugLog.logI("requestMap : " + requestMap.toString());
		}

		DebugLog.logI("method : " + method );
	}

}
